<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对象工厂派生对象并实现继承</title>
</head>
<body>
    <script>
        function User(name,age){
            this.name = name;
            this.age = age;
        }
        User.prototype.show = function(){
            console.log(this.name,this.age)
        }

        // 对象工厂
        function member(name,age){
            const instance = Object.create(User.prototype);
            User.call(instance,name,age);
            return instance;
        }
        let hd = member("hd",18);
        hd.show();


        function admin(name,age){
            const instance = Object.create(User.prototype);
            User.call(instance,name,age);
            instance.test = function(){
                console.log('test');
            };
            return instance;
        }
        let hdms = admin("hdms",19);
        hdms.show();
        hdms.test();
    </script>
</body>
</html>